package com.huike.pmps.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huike.pmps.model.entity.POCourse;
import com.huike.pmps.model.entity.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
public interface POCourseDao extends BaseMapper<POCourse> {

    //批量更新
    @Update({
            "<script>",
            "<foreach collection='list' item='item' index='index' separator=';'>",
            "update p_po_course pc",
            "set state = #{item.state}  where id= #{item.id}",
            "</foreach>",
            "</script>"
    })
    int updateStateById(List<POCourse> list);

    //根据ID 更新课程进行中时间
    @Update({"UPDATE p_po_course SET start_time = #{startTime}, course_state = '进行中'  where id= #{id}"})
    int updateStartTimeById(@Param("id")Integer id, @Param("startTime")Date startTime);


    /**
     * 更新 po课程验收单路径， po课程-供应商 验收单路径，结算单验收单路径,入库单验收单路径
     *
     * @param poCourseId
     * @param fileName
     * @param filePath
     * @param updateDate
     * @return
     */
    @Update({
            "UPDATE p_po_course SET acceptance_report_name=#{fileName}, acceptance_report_path=#{filePath},course_state='已验收',update_time=#{updateDate},recept_time=#{updateDate},recept_time_length=#{receptTimeLength} WHERE id=#{poCourseId};",
            "UPDATE p_po_course_supplier_detail SET acceptance_report_path=#{filePath} WHERE po_course_id=#{poCourseId};",
            "UPDATE p_supplier_settlement_detail SET acceptance_report_path=#{filePath} WHERE po_course_id=#{poCourseId};",
            "UPDATE p_supplier_warehouse_receipt SET supplier_info_acceptance_report_path=#{filePath} WHERE po_course_id=#{poCourseId};"
    })
    int updateAcceptanceReport(Integer poCourseId,String receptTimeLength, String fileName, String filePath, Date updateDate);


    @Insert({
            "<script>",
            "insert into pmps.p_po_course ( ",
            "  po_id,                       ",
            "  po,                          ",
            "  customer_name,               ",
            "  po_charge_id,                ",
            "  po_charge_name,              ",
            "  region_id,                   ",
            "  region_name,                 ",
            "  province_id,                 ",
            "  province_name,               ",
            "  course_id,                   ",
            "  course_name,                 ",
            "  course_type_id,              ",
            "  course_type_name,            ",
            "  course_charge_id,            ",
            "  course_charge_name,          ",
            "  subject_category_id,         ",
            "  subject_category_name,       ",
            "  major_category,              ",
            "  teacher,                     ",
            "  phone,                       ",
            "  early_exchange_id,           ",
            "  early_exchange_name,         ",
            "  estimate_quantity,           ",
            "  estimate_time_length,        ",
            "  shoot_mode_id,               ",
            "  shoot_mode_name,             ",
            "  sample_confirm,              ",
            "  shoot_start_date,            ",
            "  make_start_date,             ",
            "  project_delivery_date,       ",
            "  shoot_quantity,              ",
            "  first_edition_quantity,      ",
            "  end_edition_quantity,        ",
            "  end_edition_time_length,     ",
            "  end_edition_time_length2,    ",
            "  is_trailer,                  ",
            "  degree_of_completion,        ",
            "  is_finished,                 ",
            "  contract_amount,             ",
            "  contract_payment_received,   ",
            "  contract_outstanding_payment,",
            "  estimated_generation_cost,   ",
            "  supplier_paid_amount,        ",
            "  supplier_unpaid_amount,      ",
            "  estimated_settlement_date,   ",
            "  online_platform,             ",
            "  online_id,                   ",
            "  online_name,                 ",
            "  contract_delivery_date,      ",
            "  course_schedule_id,          ",
            "  course_schedule_name,        ",
            "  course_schedule_remark,      ",
            "  course_state,                ",
            "  acceptance_report_name,      ",
            "  acceptance_report_path,      ",
            "  acceptance_report_desc,      ",
            "  distribution_date,           ",
            "  import_flag,                 ",
            "  import_course_id,             ",
            "  state,                       ",
            "  update_time,                 ",
            "  create_time                 ",
            ")values                        ",
            "<foreach collection='poCourseList' item='item' index='index' separator=','>",
            "(											",
            "  #{item.poId},                              ",
            "  #{item.po},                                ",
            "  #{item.customerName},                      ",
            "  #{item.poChargeId},                        ",
            "  #{item.poChargeName},                      ",
            "  #{item.regionId},                          ",
            "  #{item.regionName},                        ",
            "  #{item.provinceId},                        ",
            "  #{item.provinceName},                      ",
            "  #{item.courseId},                          ",
            "  #{item.courseName},                        ",
            "  #{item.courseTypeId},                      ",
            "  #{item.courseTypeName},                    ",
            "  #{item.courseChargeId},                    ",
            "  #{item.courseChargeName},                  ",
            "  #{item.subjectCategoryId},                 ",
            "  #{item.subjectCategoryName},               ",
            "  #{item.majorCategory},                     ",
            "  #{item.teacher},                           ",
            "  #{item.phone},                             ",
            "  #{item.earlyExchangeId},                   ",
            "  #{item.earlyExchangeName},                 ",
            "  #{item.estimateQuantity},                  ",
            "  #{item.estimateTimeLength},                ",
            "  #{item.shootModeId},                       ",
            "  #{item.shootModeName},                     ",
            "  #{item.sampleConfirm},                     ",
            "  #{item.shootStartDate},                    ",
            "  #{item.makeStartDate},                     ",
            "  #{item.projectDeliveryDate},               ",
            "  #{item.shootQuantity},                     ",
            "  #{item.firstEditionQuantity},              ",
            "  #{item.endEditionQuantity},                ",
            "  #{item.endEditionTimeLength},              ",
            "  #{item.endEditionTimeLength2},             ",
            "  #{item.isTrailer},                         ",
            "  #{item.degreeOfCompletion},                ",
            "  #{item.isFinished},                        ",
            "  #{item.contractAmount},                    ",
            "  #{item.contractPaymentReceived},           ",
            "  #{item.contractOutstandingPayment},        ",
            "  #{item.estimatedGenerationCost},           ",
            "  #{item.supplierPaidAmount},                ",
            "  #{item.supplierUnpaidAmount},              ",
            "  #{item.estimatedSettlementDate},           ",
            "  #{item.onlinePlatform},                    ",
            "  #{item.onlineId},                          ",
            "  #{item.onlineName},                        ",
            "  #{item.contractDeliveryDate},              ",
            "  #{item.courseScheduleId},                  ",
            "  #{item.courseScheduleName},                ",
            "  #{item.courseScheduleRemark},              ",
            "  #{item.courseState},                       ",
            "  #{item.acceptanceReportName},              ",
            "  #{item.acceptanceReportPath},              ",
            "  #{item.acceptanceReportDesc},              ",
            "  #{item.distributionDate},                  ",
            "  #{item.importFlag},                        ",
            "  #{item.importCourseId},                    ",
            "  #{item.state},                             ",
            "  #{item.updateTime},                        ",
            "  #{item.createTime}                         ",
            ")                                            ",
            "</foreach>",
            "</script>"
    })
    int insertByImportPoCourse(@Param(value = "poCourseList")List<POCourse> poCourseList);

    /**
     * add by zcw 2021-07-06 根据课程ID查询课程状态
     * @param id
     * @return
     */
    @Select(" select course_state from p_po_course where id = #{id}")
    String selectPoCourseStateById(Integer id);
}
